import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * @author Yuri Denison
 * @since 15.08.11
 */
public class Transformations {
    private JComboBox state1Box;
    private JComboBox state2Box;
    private JTextField transformationText;
    private JPanel mainPanel;
    private JPanel textPanel;

    private JFrame frame;
    private static final String NO_TRANSFORMATION = "No such transformation";

    public Transformations() {
        for (Main.State state : Main.State.values()) {
            state1Box.addItem(state);
            state2Box.addItem(state);
        }

        ItemListener listener = new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                Main.State s1 = (Main.State) state1Box.getSelectedItem();
                Main.State s2 = (Main.State) state2Box.getSelectedItem();
                Main.Transformation t = Main.getTransformation(s1, s2);

                String text = (t != null) ? t.name() : NO_TRANSFORMATION;
                transformationText.setText(text);
            }
        };

        state1Box.addItemListener(listener);
        state2Box.addItemListener(listener);
    }

    public void showForm() {
        frame = new JFrame("Transformations");
        frame.setContentPane(mainPanel);
        frame.setMinimumSize(new Dimension(300, 300));
        frame.pack();
        frame.setLocation(150, 150);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setVisible(true);
    }
}
